package com.xxdemo.quickstart.database.table;

import com.xxdemo.quickstart.MyApplicationRuntimeException;
import org.apache.commons.lang3.StringUtils;

public class Column {
    private String name = null;

    public Column(String columnName) {
        setName(columnName);
    }

    public String getName() {
        return name;
    }

    private void setName(String columnName) {
        if (StringUtils.isBlank(columnName)) { // 需检查null指针,空字符串,以及若干空格,tab,回车这些不可打印字符
            throw new ColumnNameShouldNotBeBlank();
        }
        columnName = columnName.replaceAll("`", "").toLowerCase().trim();
        name = String.format("`%s`", columnName);

    }

    public static class ColumnNameShouldNotBeBlank extends MyApplicationRuntimeException {
    }
}
